package com.oocl.im.parser.impl;

import com.oocl.im.parser.IParser;
import com.oocl.im.constants.ServerConstants;
import com.oocl.im.entity.Protocol;
import com.oocl.im.handler.IHandle;
import com.oocl.im.handler.impl.LoginHandle;
import com.oocl.im.handler.impl.LogoutHandle;
import com.oocl.im.handler.impl.ChatHandle;
import com.oocl.im.handler.impl.ShakeHandle;

import java.io.ObjectOutputStream;


public class Parse implements IParser {
    ObjectOutputStream oos ;

    public Parse(ObjectOutputStream oos) {
        this.oos = oos;
    }

    @Override
    public IHandle parse(Protocol protocol) {

        IHandle handle = null;
       String msgtype=protocol.getMsgType();
        if (ServerConstants.LOGIN.equals(msgtype)) {
            System.out.println("parse is login");
            handle = new LoginHandle(oos);
        }
        if (ServerConstants.LOGOUT.equals(msgtype)) {
            System.out.println("parse is logout");
            handle = new LogoutHandle(oos);
        }
        if (ServerConstants.CHAT.equals(msgtype)) {
            handle = new ChatHandle(oos);
        }
        if (ServerConstants.SHAKE.equals(msgtype))
        {
            handle=new ShakeHandle(oos);
        }
        return handle;
    }

}
